/**
 * @author monirul
 */
goog.require('goog.dom');
goog.require('goog.fx.DragDropGroup');
  
var GameCardView =  new Class.create({
	
	initialize: function(){
		this._id;
		this._playerId;
		this._icon;
		this._width;
		this._height;
		this._parentId;
		this._className;
		this._conf;
		this._metaInfo = {};
	},
	
	init:function(o){
		var _this = this;
		if(o['model'] != null) this._model = o['model'];
		if(o['controller'] != null) this._controller = o['controller'];
		if(o['elements'] != null){
			this._elements = o['elements'];
			this._targetLocation = this._elements['targetLocation'];
		}	
		if(o['conf'] != null){
			this._conf = o['conf'];
			this._width = this._conf.width ;
			this._height = this._conf.height;
			this._parentId = this._conf.parentId;
			this._className = this._conf.className;
			this._playerId = this._conf.playerId;
//			this._id = this._conf.playerId +"_card_"+this._conf.cardIndex;
			this._metaInfo["card_id"] = this._id;
			this._metaInfo["card_type"] = this._model.getCardType();
		}	
		// attach model listeners
	    this._model.gameCardInitialized.attach(function () {
	        _this._rebuild();
	    });
	    
	    this._model.gameCardActivated.attach(function () {
	        _this._cardActivation();
	    });
	   
	},
	show : function () {
        this._rebuild();
	},
	
	_cardActivation:function(){
		var _this = this;
		if(this._model.isActive()){
			goog.events.listen(this._targetLocation, 'click',
			        function(e) {
			    		alert('Selected _cardActivation');
			    		_this.setSelected();
			    });
		}else{
			goog.events.listen(this._targetLocation, 'click',
			        function(e) {
			    		alert('Not active ');
			    });
		}
	},
	
	_init_dom:function(){
		var _this = this; 
		var cardDisplayName = this._model.getCardDisplayName();
		this._cardElement = goog.dom.createDom('div', {'style': '','id':this._id },this._model.getCardDisplayName())
		
		this._targetLocation = $(this._parentId);
//		goog.dom.removeChildren(this._targetLocation);
		goog.dom.appendChild(this._targetLocation, this._cardElement);
		goog.events.listen(this._targetLocation, 'click',
		        function(e) {
		    		alert('Selected init');
		    		_this.setSelected();
		    });
	},
	
	setSelected:function(){
		this._targetLocation.style.border = '2px solid white';
		this._model.setSelected(true);
		var list1 = new goog.fx.DragDropGroup(this._targetLocation);
		list1.init();
		
		

//		goog.events.listen(this._targetLocation, 'dragover', dragOver);
//		goog.events.listen(this._targetLocation, 'dragout', dragOut);
//		goog.events.listen(this._targetLocation, 'drop', drop);
		goog.events.listen(this._targetLocation, 'dragstart', function(){alert('drag start');});
		goog.events.listen(this._targetLocation, 'dragend', function(){alert('drag end');});


		
		
//		if(this._model.getCardType() == "arm"){
//			ddManager.registerDDItem(this._id, [this._model.getCardType()], {}, this._metaInfo);
//		}else{
//			ddManager.registerDDItem(this._id, ["attack_"+this._model.getCardDistance()], {}, this._metaInfo);
//		}
	},
	
	_rebuild: function() {
		this._init_dom()
	}
	
});
